package org.www.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.www.bean.User;
import org.www.dao.UserDao;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class UserAction extends ActionSupport implements ModelDriven<User> {
	private User user=new User();
	private UserDao userdao=new UserDao();
	private List<User> list=new ArrayList<User>();
	private Map map;
	
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public UserDao getUserdao() {
		return userdao;
	}
	public void setUserdao(UserDao userdao) {
		this.userdao = userdao;
	}
	public List<User> getList() {
		return list;
	}
	public void setList(List<User> list) {
		this.list = list;
	}
	
	
	public Map getMap() {
		return map;
	}
	public void setMap(Map map) {
		this.map = map;
	}
	public String login(){
		if(userdao.login(user.getUname(), user.getPassword())) {
			return SUCCESS;
		}
		return ERROR;
		}
	 public String deleteUserById() {
	    	userdao.deleteUser(user);
			return SUCCESS;    	
	    }
    public String getUserById() {
    	user=userdao.findUserById(user.getUid());
		return SUCCESS;
    	
    }
	public String showAll() {
		map=new HashMap();
		list=userdao.findAll();
		map.put("code1", list);
		return SUCCESS;
	}
	
	public String add() {
		userdao.addUser(user);
		return SUCCESS;
		
	}
	
	public String update() {
	  userdao.updateUser(user);
		return SUCCESS;
		
	}
	@Override
	public User getModel() {
		// TODO Auto-generated method stub
		return user;
	}
	
	

}
